﻿-- Extermina los que se fueron repetidos
	DECLARE A CURSOR FOR
		SELECT ID FROM
		(SELECT ROW_NUMBER () OVER (PARTITION BY [Name] ORDER BY [Name])  i, ID, BasicReferenceTypeID, Name FROM esf_sso.BasicReference) X
		WHERE X.i > 1

	DECLARE @ID INT

	OPEN A

	FETCH NEXT FROM A INTO @ID

	WHILE @@FETCH_STATUS = 0
	BEGIN

		print 'quitando a '  + convert (varchar (30), @ID)

		DELETE FROM esf_sso.BasicReference WHERE ID = @ID

		FETCH NEXT FROM A INTO @ID
	END


	CLOSE A
	DEALLOCATE A